package com.canbot.u05.activity.shoppingGuide.sales;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;

import com.canbot.u05.R;
import com.canbot.u05.activity.BaseActivityNoTitle;
import com.canbot.u05.activity.shoppingGuide.advisory.SettingAdvisoryActivity;
import com.canbot.u05.activity.shoppingGuide.codeMarketing.CodeMainActivity;
import com.canbot.u05.activity.shoppingGuide.merchandiseShoppingGuide.SelectSettingTypeActivity;
import com.canbot.u05.activity.reception.ReceptionModeSettingActivity;
import com.canbot.u05.socket.MsgSendUtils;
import com.canbot.u05.socket.MsgType;


/**
 * 导购模式主界面
 */
public class SaleEnterActivity extends BaseActivityNoTitle {


        private GridView mGridView;

        private int[] icon_ids = {R.drawable.icon_men_welcome_selector, R.drawable.icon_site_selector, R.drawable.icon_basket_selector,
                R.drawable.icon_promotion_selector, R.drawable.icon_consult_selector,R.drawable.icon_code_marketing_selector};

        private String[] names = {"门童接待", "地点问询", "商品导购", "促销揽客", "咨询问答","二维码营销"};

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                //                setContentView(R.layout.act_sale_enter);
                setContentView(R.layout.activity_sale_setting);

                mGridView = (GridView) findViewById(R.id.gridView);


                initData();
        }

        public void initData() {
                mGridView.setAdapter(new OfficeSettingAdapter());
                mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                itemClick(position);
                        }
                });
        }

        /**
         * GridView item 点击处理
         *
         * @param position gridView position
         */
        private void itemClick(int position) {
                switch (position) {
                        case 0:
                                saleMenWelcome();
                                break;
                        case 1:
                                site();
                                break;
                        case 2:
                                basket();
                                break;
                        case 3:
                                promotion();
                                break;
                        case 4:
                                consult();
                                break;
                        case 5:
                                codeMarketing();
                                break;
                }
        }

        private void codeMarketing() {
                Intent intent = new Intent(this, CodeMainActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
        }

        /**
         * 返回
         */
        public void saleBack(View view) {
                finish();
                overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
        }

        /**
         * 门童接待
         */
        public void saleMenWelcome() {
                MsgSendUtils.sendStringMsg(MsgType.SEND_PAD_MEETING_START, "handSetting");
                Intent intent = new Intent(this, ReceptionModeSettingActivity.class);
                startActivity(intent);
                overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
        }

        /**
         * 地点问询
         */
        public void site() {


                        //进入路线指引设置
                        startActivity(new Intent(this, RouteActivity.class));
                        overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);

        }

        /**
         * 商品导购
         */
        public void basket() {
                Intent intent = new Intent(this, SelectSettingTypeActivity.class);
                intent.putExtra("isFirst", true);
                startActivity(intent);
                overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
                //                startotherActivity(SaleEnterActivity.this, SelectSettingTypeActivity.class);
        }

        /**
         * 促销揽客
         */
        public void promotion() {
                Intent intent = new Intent(this, SellModePropagandaActivity.class);
                intent.putExtra("isFirst", true);
                startActivity(intent);
                overridePendingTransition(R.anim.face_zoom_enter,
                        R.anim.face_zoom_exit);
        }

        /**
         * 咨询问答
         */
        public void consult() {
                Intent intent = new Intent(this, SettingAdvisoryActivity.class);
                intent.putExtra("isFirst", true);
                startActivity(intent);
                overridePendingTransition(R.anim.face_zoom_enter, R.anim.face_zoom_exit);
                //                startotherActivity(SaleEnterActivity.this, SettingAdvisoryActivity.class);
        }

        /**
         * 舞蹈表演
         */
        public void perform() {

        }

        /**
         * 售后服务
         */
        public void phone() {

        }

        /**
         * 会员管理
         */
        public void card() {

        }

        /**
         * 付款结账
         */
        public void payment() {

        }

        /**
         * 信息登记
         */
        public void register() {
        }


        @Override
        protected void onResume() {
                super.onResume();
                MsgSendUtils.sendStringMsg(MsgType.EYE_MOTION, "14");
        }

        @Override
        protected void onPause() {
                super.onPause();

        }

        private class OfficeSettingAdapter extends BaseAdapter {

                @Override
                public int getCount() {
                        return icon_ids.length;
                }

                @Override
                public Object getItem(int position) {
                        return position;
                }

                @Override
                public long getItemId(int position) {
                        return position;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                        ViewHolder mHolder;
                        if (convertView == null) {
                                mHolder = new ViewHolder();
                                convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_office_setting, parent, false);
                                mHolder.btn = (Button) convertView.findViewById(R.id.btn);
                                mHolder.name = (TextView) convertView.findViewById(R.id.name);
                                convertView.setTag(mHolder);
                        }
                        else {
                                mHolder = (ViewHolder) convertView.getTag();
                        }

                        mHolder.btn.setBackgroundResource(icon_ids[position]);
                        mHolder.name.setText(names[position]);

                        return convertView;
                }

        }

        static class ViewHolder {

                private Button btn;

                private TextView name;
        }

}
